
const app = getApp()
const $api = require('../../../utils/api.js').API;

Page({
    data: {
        page: 1,
        noneShow:false,
        list:[],
        pageShow:true,
        imgUrl:app.globalData.imgUrl,
    },
    onLoad:function(){
        this.getlist();
    },
    onShow: function(){
        
    },
    getlist: function(){
        wx.showLoading()
        var that = this
        var data ={
            'uid':wx.getStorageSync('uid'),
            'page':this.data.page
        }
        $api.get('order/list',data).then(res => {
            if(res.data.code == 1){
                wx.hideLoading()
                if(res.data.data.total == 0){
                    that.setData({
                        noneShow:true
                    })
                }else{
                    that.setData({
                        noneShow:false
                    })
                }
                if(res.data.data.last_page <= that.data.page){
                    that.setData({
                        pageShow:false
                    })
                }
                var list = that.data.list
                if(that.data.page == 1){
                    that.setData({
                        list:res.data.data.data
                    })
                }else{
                    that.setData({
                        list:list.concat(res.data.data.data)
                    })
                }
            }
        }).catch(err => {
            //请求失败
            //console.log('error',err);
        })
    },
    onReachBottom: function(t){
        if(this.data.pageShow){
            //当前不是最后一页可加载
            this.setData({
                page: this.data.page + 1,
            })
        this.getlist();
        }
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    },
    orderDelete:function(e){
        var id = e.target.dataset.id;
        var data = {'id':id}
        var that = this
        $api.put('order/edit',data).then(res => {
            if(res.data.code == 1){
                wx.showToast({
                    title:'成功!!!',
                    duration:2000,//显示时长
                    mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
                    icon:'none', //图标，支持"success"、"loading" 
                })
                that.setData({
                    list:[],
                    page:1
                })
                that.getlist()
            }
        })
    }
});